package com.leyou.trade.web;

import com.leyou.trade.dto.OrderDTO;
import com.leyou.trade.dto.OrderFormDTO;
import com.leyou.trade.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    //创建订单(返回订单id,用于生成付款信息)
    @PostMapping
    public ResponseEntity<Long> createOrder(@RequestBody OrderFormDTO orderFormDTO) {
        return ResponseEntity.status(HttpStatus.CREATED).body(orderService.createOrder(orderFormDTO));
    }
    //根据id查询订单,用于付款时回显
    @GetMapping("{id}")
    public ResponseEntity<OrderDTO> queryOrderById(@PathVariable("id") Long orderId){
        return ResponseEntity.ok(new OrderDTO(orderService.getById(orderId)));
    }
}

